package Acwing;

import java.util.Stack;

public class Acwing17 {
    public int[] printListReversingly(ListNode head) {
          Stack<Integer> stack=new Stack<>();
          ListNode tmp=head;
          while(tmp!=null){
              stack.add(tmp.val);
              tmp=tmp.next;
          }
          int index=0;
          int[] arr=new int[stack.size()];
          while(!stack.isEmpty()){
              arr[index++]=stack.pop();
          }
          return arr;
    }
}
class ListNode {
    int val;
    ListNode next;
    ListNode(int x) { val = x; }
}